FROM openanolis/anolisos:8.6

LABEL \
	org.opencontainers.image.title="mysql" \
	org.opencontainers.image.version="8.0.30-8.6"

RUN set -eux; \
	yum -y update; \
	yum -y install mysql mysql-server wget; \
	yum clean all

ARG TARGETARCH

ENV GOSU_VERSION 1.14

RUN set -eux; \
        wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH"; \
        wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH.asc"; \
        export GNUPGHOME="$(mktemp -d)"; \
        gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
        gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
        gpgconf --kill all; \
        rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
        chmod +x /usr/local/bin/gosu; \
        gosu --version; \
        gosu nobody true

RUN set -eux; \
	rm -rf /var/lib/mysql; \
	mkdir -p /var/lib/mysql /var/run/mysqld; \
	chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; \
	chmod 1777 /var/run/mysqld /var/lib/mysql; \
	mkdir /docker-entrypoint-initdb.d; \
# Avoid mysqld permission denied. Docker scenaio do not need this.
	setcap -r /usr/libexec/mysqld;\
	mysqld --version; \
	mysql --version

ENV MYSQL_MAJOR 8.0

ENV MYSQL_VERSION 8.0.30

VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /usr/local/bin/

COPY config/ /etc/mysql/

RUN set -eux; \
	ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh; \
	mv /etc/my.cnf.d/* /etc/mysql/conf.d/; \
	rm -rf /etc/my.cnf /etc/my.cnf.d/

ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 3306 33060

CMD ["mysqld"]
